package com.portico.dept.solarch

class ProjectStatus {

  String trend ;
  String status;
  String statusType ="Weekly";
  String scope;
  String projectPlan;
  String governance;
  String resources;
  String voc;
  String timeline;
  String qualityOfRequirements;
  String qualityOfDesign
  String qualityOfCode
  String qualityOfBuild
  Date statusDate
  Date createdOn 
  Date lastUpdated
  Project project

  static constraints = {
    trend(inList:["Green->Green", "Green->Yellow","Green -> Red" , "Yellow->Yellow", "Yellow -> Green", "Yellow -> Red", "Red -> Red", "Red -> Yellow", "Red -> Green"]);
    status(shared: "RYGList")
    //statusType(shared: "ProjectStatusType")
    scope(shared: "RYGList")
    projectPlan(shared: "RYGList")
    governance(shared: "RYGList")
    resources(shared: "RYGList")
    voc(shared: "RYGList")
    timeline(shared: "RYGList")
    qualityOfRequirements(shared: "RYGList")
    qualityOfDesign(shared: "RYGList")
    qualityOfCode(shared: "RYGList")
    qualityOfBuild(shared: "RYGList")
    statusDate(blank: false)
    createdOn(blank: false)
    lastUpdated(validator: {
      lastUpdated, obj ->
      if (lastUpdated != null && obj.createdOn != null) {
        return lastUpdated.after(obj.createdOn)
      }
      return true
    })
  }

  static hasMany = [comments: ProjectStatusComment]

  static belongsTo = [project: Project]
  static String CSV_HEADER = """project.id  ,  project.name  , status  ,  statusType  ,  scope  ,  projectPlan  , governance  ,  resources  ,  voc  , timeline  ,  qualityOfRequirements  , qualityOfDesign  ,  qualityOfCode  ,  qualityOfBuild  , statusDate  ,  createdOn  ,  lastUpdated""" ;


  String toString() {
    "${statusType} - ${createdOn}"
  }

  //static String

  static mapping = {
    sort 'statusDate'
  }

  String toCSVString() {
    project.id + "," + project.name + "," +
            status + "," + statusType + "," + scope + "," + projectPlan + "," +
            governance + "," + resources + "," + voc + "," +
            timeline + "," + qualityOfRequirements + "," +
            qualityOfDesign + "," + qualityOfCode + "," + qualityOfBuild + "," +
            statusDate + "," + createdOn + "," + lastUpdated;

  }
}
